<?php
header('Content-Type: text/html; charset=utf-8');

//requires
require_once('StringAnalizator/StringAnalizator.php');
require_once('StringAnalizator/StringLoadingStrategy/SimpleStringLoadingStrategy.php');
require_once('StringAnalizator/StringLoadingStrategy/RandomStringLoadingStrategy.php');
require_once('StringAnalizator/AnalyzeStrategy/CapitalLettersAnalyzeStrategy.php');
require_once('StringAnalizator/AnalyzeStrategy/SmallLettersAnalyzeStrategy.php');
require_once('StringAnalizator/AnalyzeStrategy/RepeatLettersAnalyzeStrategy.php');

if (!isset($_GET['param'])) {
    return false;
}

$param = $_GET['param'];

if ((int) $param != 0) {
    $stringLoadingStrategy = new RandomStringLoadingStrategy();
} else {
    $stringLoadingStrategy = new SimpleStringLoadingStrategy();
}

$capitalLettersStringAnalizator = new StringAnalizator($stringLoadingStrategy, new CapitalLettersAnalyzeStrategy(), $param);
$smallLettersStringAnalizator = new StringAnalizator($stringLoadingStrategy, new SmallLettersAnalyzeStrategy(), $param);
$repeatLettersStringAnalizator = new StringAnalizator($stringLoadingStrategy, new RepeatLettersAnalyzeStrategy(), $param);
?>
Строка 1: <?php echo $capitalLettersStringAnalizator->getString(); ?><br/>
Количество заглавных букв: <?php echo $capitalLettersStringAnalizator->analyze(); ?><br/><br/>
Строка 2: <?php echo $smallLettersStringAnalizator->getString(); ?><br/>
Количество заглавных букв: <?php echo $smallLettersStringAnalizator->analyze(); ?><br/><br/>
Строка 3: <?php echo $repeatLettersStringAnalizator->getString(); ?><br/>
<?php
$repeats = $repeatLettersStringAnalizator->analyze();

$jsArray = array();
foreach ($repeats as $letter => $count) {
    $jsArray[] = "['{$letter}', {$count}]";
}

$jsArray = implode(',', $jsArray);

?>

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
    
    // Load the Visualization API and the piechart package.
    google.load('visualization', '1.0', {'packages':['corechart']});
      
    // Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(drawChart);
      
    // Callback that creates and populates a data table, 
    // instantiates the pie chart, passes in the data and
    // draws it.
    function drawChart() {

        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Topping');
        data.addColumn('number', 'Slices');
        data.addRows([
            <?php echo $jsArray; ?>
        ]);

        // Set chart options
        var options = {'title':'Repeat analyze',
            'width':500,
            'height':500};

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
    }
</script>
<div id="chart_div"></div>